From 63e6bc43a1093535d0938acc577a7fe1f6c351c5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 30 Jun 2020 23:29:25 +0900 Subject: [PATCH 1/4] Update nuget package and add ranking result test case. --- .../Ranking/TestSceneResultsScreen.cs | 323 ++++++++++++++++++ .../Skinning/KaraokeSkinnableTestScene.cs | 9 - .../osu.Game.Rulesets.Karaoke.csproj | 4 +- 3 files changed, 325 insertions(+), 11 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs new file mode 100644 index 000000000..86fb972c6 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs @@ -0,0 +1,323 @@ +// 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.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Screens; +using osu.Framework.Testing; +using osu.Framework.Utils; +using osu.Game.Beatmaps; +using osu.Game.Online.API; +using osu.Game.Scoring; +using osu.Game.Screens; +using osu.Game.Screens.Play; +using osu.Game.Screens.Ranking; +using osu.Game.Screens.Ranking.Statistics; +using osu.Game.Tests; +using osu.Game.Tests.Visual; +using osuTK; +using osuTK.Input; + +namespace osu.Game.Rulesets.Karaoke.Tests.Ranking +{ + [TestFixture] + public class TestSceneResultsScreen : OsuManualInputManagerTestScene + { + private BeatmapManager beatmaps; + + [BackgroundDependencyLoader] + private void load(BeatmapManager beatmaps) + { + this.beatmaps = beatmaps; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0); + if (beatmapInfo != null) + Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo); + } + + private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); + + private UnrankedSoloResultsScreen createUnrankedSoloResultsScreen() => new UnrankedSoloResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); + + [Test] + public void TestResultsWithoutPlayer() + { + TestResultsScreen screen = null; + OsuScreenStack stack; + + AddStep("load results", () => + { + Child = stack = new OsuScreenStack + { + RelativeSizeAxes = Axes.Both + }; + + stack.Push(screen = createResultsScreen()); + }); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + AddAssert("retry overlay not present", () => screen.RetryOverlay == null); + } + + [Test] + public void TestResultsWithPlayer() + { + TestResultsScreen screen = null; + + AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + AddAssert("retry overlay present", () => screen.RetryOverlay != null); + } + + [Test] + public void TestResultsForUnranked() + { + UnrankedSoloResultsScreen screen = null; + + AddStep("load results", () => Child = new TestResultsContainer(screen = createUnrankedSoloResultsScreen())); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + AddAssert("retry overlay present", () => screen.RetryOverlay != null); + } + + [Test] + public void TestShowHideStatisticsViaOutsideClick() + { + TestResultsScreen screen = null; + + AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + + AddStep("click expanded panel", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + InputManager.MoveMouseTo(expandedPanel); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("statistics shown", () => this.ChildrenOfType().Single().State.Value == Visibility.Visible); + + AddUntilStep("expanded panel at the left of the screen", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + return expandedPanel.ScreenSpaceDrawQuad.TopLeft.X - screen.ScreenSpaceDrawQuad.TopLeft.X < 150; + }); + + AddStep("click to right of panel", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + InputManager.MoveMouseTo(expandedPanel.ScreenSpaceDrawQuad.TopRight + new Vector2(100, 0)); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("statistics hidden", () => this.ChildrenOfType().Single().State.Value == Visibility.Hidden); + + AddUntilStep("expanded panel in centre of screen", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + return Precision.AlmostEquals(expandedPanel.ScreenSpaceDrawQuad.Centre.X, screen.ScreenSpaceDrawQuad.Centre.X, 1); + }); + } + + [Test] + public void TestShowHideStatistics() + { + TestResultsScreen screen = null; + + AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + + AddStep("click expanded panel", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + InputManager.MoveMouseTo(expandedPanel); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("statistics shown", () => this.ChildrenOfType().Single().State.Value == Visibility.Visible); + + AddUntilStep("expanded panel at the left of the screen", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + return expandedPanel.ScreenSpaceDrawQuad.TopLeft.X - screen.ScreenSpaceDrawQuad.TopLeft.X < 150; + }); + + AddStep("click expanded panel", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + InputManager.MoveMouseTo(expandedPanel); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("statistics hidden", () => this.ChildrenOfType().Single().State.Value == Visibility.Hidden); + + AddUntilStep("expanded panel in centre of screen", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + return Precision.AlmostEquals(expandedPanel.ScreenSpaceDrawQuad.Centre.X, screen.ScreenSpaceDrawQuad.Centre.X, 1); + }); + } + + [Test] + public void TestShowStatisticsAndClickOtherPanel() + { + TestResultsScreen screen = null; + + AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + + ScorePanel expandedPanel = null; + ScorePanel contractedPanel = null; + + AddStep("click expanded panel then contracted panel", () => + { + expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + InputManager.MoveMouseTo(expandedPanel); + InputManager.Click(MouseButton.Left); + + contractedPanel = this.ChildrenOfType().First(p => p.State == PanelState.Contracted && p.ScreenSpaceDrawQuad.TopLeft.X > screen.ScreenSpaceDrawQuad.TopLeft.X); + InputManager.MoveMouseTo(contractedPanel); + InputManager.Click(MouseButton.Left); + }); + + AddAssert("statistics shown", () => this.ChildrenOfType().Single().State.Value == Visibility.Visible); + + AddAssert("contracted panel still contracted", () => contractedPanel.State == PanelState.Contracted); + AddAssert("expanded panel still expanded", () => expandedPanel.State == PanelState.Expanded); + } + + [Test] + public void TestFetchScoresAfterShowingStatistics() + { + DelayedFetchResultsScreen screen = null; + + AddStep("load results", () => Child = new TestResultsContainer(screen = new DelayedFetchResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo), 3000))); + AddUntilStep("wait for loaded", () => screen.IsLoaded); + AddStep("click expanded panel", () => + { + var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); + InputManager.MoveMouseTo(expandedPanel); + InputManager.Click(MouseButton.Left); + }); + + AddUntilStep("wait for fetch", () => screen.FetchCompleted); + AddAssert("expanded panel still on screen", () => this.ChildrenOfType().Single(p => p.State == PanelState.Expanded).ScreenSpaceDrawQuad.TopLeft.X > 0); + } + + private class TestResultsContainer : Container + { + [Cached(typeof(Player))] + private readonly Player player = new TestPlayer(); + + public TestResultsContainer(IScreen screen) + { + RelativeSizeAxes = Axes.Both; + OsuScreenStack stack; + + InternalChild = stack = new OsuScreenStack + { + RelativeSizeAxes = Axes.Both, + }; + + stack.Push(screen); + } + } + + private class TestResultsScreen : ResultsScreen + { + public HotkeyRetryOverlay RetryOverlay; + + public TestResultsScreen(ScoreInfo score) + : base(score) + { + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + RetryOverlay = InternalChildren.OfType().SingleOrDefault(); + } + + protected override APIRequest FetchScores(Action> scoresCallback) + { + var scores = new List(); + + for (int i = 0; i < 20; i++) + { + var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo); + score.TotalScore += 10 - i; + scores.Add(score); + } + + scoresCallback?.Invoke(scores); + + return null; + } + } + + private class DelayedFetchResultsScreen : TestResultsScreen + { + public bool FetchCompleted { get; private set; } + + private readonly double delay; + + public DelayedFetchResultsScreen(ScoreInfo score, double delay) + : base(score) + { + this.delay = delay; + } + + protected override APIRequest FetchScores(Action> scoresCallback) + { + Task.Run(async () => + { + await Task.Delay(TimeSpan.FromMilliseconds(delay)); + + var scores = new List(); + + for (int i = 0; i < 20; i++) + { + var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo); + score.TotalScore += 10 - i; + scores.Add(score); + } + + scoresCallback?.Invoke(scores); + + Schedule(() => FetchCompleted = true); + }); + + return null; + } + } + + private class UnrankedSoloResultsScreen : SoloResultsScreen + { + public HotkeyRetryOverlay RetryOverlay; + + public UnrankedSoloResultsScreen(ScoreInfo score) + : base(score) + { + Score.Beatmap.OnlineBeatmapID = 0; + Score.Beatmap.Status = BeatmapSetOnlineStatus.Pending; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + RetryOverlay = InternalChildren.OfType().SingleOrDefault(); + } + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinnableTestScene.cs b/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinnableTestScene.cs index ee9b1148e..e07d4ff9f 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinnableTestScene.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinnableTestScene.cs @@ -1,23 +1,14 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System; -using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Karaoke.Beatmaps; -using osu.Game.Rulesets.Karaoke.Skinning; using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Karaoke.Tests.Skinning { public abstract class KaraokeSkinnableTestScene : SkinnableTestScene { - public override IReadOnlyList RequiredTypes => new[] - { - typeof(KaraokeRuleset), - typeof(KaraokeLegacySkinTransformer), - }; - protected override Ruleset CreateRulesetForSkinProvider() => new KaraokeRuleset(); protected override IBeatmap CreateBeatmapForSkinProvider() => new KaraokeBeatmap(); diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index 3606e1f46..0f99a7653 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -10,9 +10,9 @@ - + - + From 92854d6e5ad2855846cebfb832ad4133a8163945 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 1 Jul 2020 00:18:10 +0900 Subject: [PATCH 2/4] Add default statistics for score and statistics panel test case. --- .../Ranking/TestSceneResultsScreen.cs | 18 +------ .../Ranking/TestSceneStatisticsPanel.cs | 52 +++++++++++++++++++ osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs | 19 +++++++ 3 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs index 86fb972c6..ae64a6ea8 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs @@ -14,6 +14,7 @@ using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Online.API; +using osu.Game.Rulesets.Karaoke.Tests.Beatmaps; using osu.Game.Scoring; using osu.Game.Screens; using osu.Game.Screens.Play; @@ -29,22 +30,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Ranking [TestFixture] public class TestSceneResultsScreen : OsuManualInputManagerTestScene { - private BeatmapManager beatmaps; - - [BackgroundDependencyLoader] - private void load(BeatmapManager beatmaps) - { - this.beatmaps = beatmaps; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0); - if (beatmapInfo != null) - Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo); - } + protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestKaraokeBeatmap(ruleset); private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs new file mode 100644 index 000000000..8266a171b --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs @@ -0,0 +1,52 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring; +using osu.Game.Screens.Ranking.Statistics; +using osu.Game.Tests; +using osu.Game.Tests.Visual; +using System.Collections.Generic; + +namespace osu.Game.Rulesets.Karaoke.Tests.Ranking +{ + public class TestSceneStatisticsPanel : OsuTestScene + { + [Test] + public void TestScoreWithStatistics() + { + var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo) + { + //TODO : add hit event. + HitEvents = new List() + }; + + loadPanel(score); + } + + [Test] + public void TestScoreWithoutStatistics() + { + loadPanel(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); + } + + [Test] + public void TestNullScore() + { + loadPanel(null); + } + + private void loadPanel(ScoreInfo score) => AddStep("load panel", () => + { + Child = new StatisticsPanel + { + RelativeSizeAxes = Axes.Both, + State = { Value = Visibility.Visible }, + Score = { Value = score } + }; + }); + } +} diff --git a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs index f5b6c953e..fe36f7c49 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Framework.Input.Bindings; @@ -18,6 +19,7 @@ using osu.Game.Rulesets.Karaoke.Difficulty; using osu.Game.Rulesets.Karaoke.Edit; using osu.Game.Rulesets.Karaoke.Mods; +using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Replays; using osu.Game.Rulesets.Karaoke.Resources.Fonts; using osu.Game.Rulesets.Karaoke.Scoring; @@ -27,6 +29,8 @@ using osu.Game.Rulesets.Replays.Types; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; +using osu.Game.Scoring; +using osu.Game.Screens.Ranking.Statistics; using osu.Game.Skinning; namespace osu.Game.Rulesets.Karaoke @@ -140,6 +144,21 @@ public override IEnumerable GetModsFor(ModType type) public override RulesetSettingsSubsection CreateSettings() => new KaraokeSettingsSubsection(this); + public override StatisticRow[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => new[] + { + new StatisticRow + { + Columns = new[] + { + new StatisticItem("Timing Distribution", new HitEventTimingDistributionGraph(score.HitEvents.Where(e => e.HitObject is Note).ToList()) + { + RelativeSizeAxes = Axes.X, + Height = 250 + }), + } + } + }; + public KaraokeRuleset() { // It's a tricky to let osu! to read karaoke testing beatmap From faecef999897bf0127c884e8d131eb4ddd6b7d3a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 2 Jul 2020 21:47:21 +0900 Subject: [PATCH 3/4] Add some test case. --- .../Ranking/TestKaraokeScoreInfo.cs | 44 ++++++++++++ ...estSceneHitEventTimingDistributionGraph.cs | 72 +++++++++++++++++++ .../Ranking/TestSceneResultsScreen.cs | 2 +- .../Ranking/TestSceneStatisticsPanel.cs | 10 ++- 4 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneHitEventTimingDistributionGraph.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs new file mode 100644 index 000000000..6d7c6f547 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs @@ -0,0 +1,44 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Game.Rulesets.Karaoke.Mods; +using osu.Game.Rulesets.Karaoke.Tests.Beatmaps; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring; +using osu.Game.Users; + +namespace osu.Game.Rulesets.Karaoke.Tests.Ranking +{ + public class TestKaraokeScoreInfo : ScoreInfo + { + public TestKaraokeScoreInfo() + { + var ruleset = new KaraokeRuleset().RulesetInfo; + + User = new User + { + Id = 11111, + Username = "andy840119", + CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", + }; + + Beatmap = new TestKaraokeBeatmap(ruleset).BeatmapInfo; + Ruleset = ruleset; + RulesetID = ruleset.ID ?? 0; + Mods = new Mod[] { new KaraokeModFlashlight(), new KaraokeModSnow() }; + + TotalScore = 2845370; + Accuracy = 0.95; + MaxCombo = 999; + Rank = ScoreRank.S; + Date = DateTimeOffset.Now; + + Statistics[HitResult.Miss] = 1; + Statistics[HitResult.Meh] = 50; + Statistics[HitResult.Good] = 100; + Statistics[HitResult.Great] = 300; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneHitEventTimingDistributionGraph.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneHitEventTimingDistributionGraph.cs new file mode 100644 index 000000000..6a406b3fc --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneHitEventTimingDistributionGraph.cs @@ -0,0 +1,72 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Shapes; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Scoring; +using osu.Game.Screens.Ranking.Statistics; +using osu.Game.Tests.Visual; +using osuTK; + +namespace osu.Game.Rulesets.Karaoke.Tests.Ranking +{ + public class TestSceneHitEventTimingDistributionGraph : OsuTestScene + { + [Test] + public void TestManyDistributedEvents() + { + createTest(CreateDistributedHitEvents()); + } + + [Test] + public void TestZeroTimeOffset() + { + createTest(Enumerable.Range(0, 100).Select(_ => new HitEvent(0, HitResult.Perfect, new Note(), new Note(), null)).ToList()); + } + + [Test] + public void TestNoEvents() + { + createTest(new List()); + } + + private void createTest(List events) => AddStep("create test", () => + { + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = Color4Extensions.FromHex("#333") + }, + new HitEventTimingDistributionGraph(events) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(600, 130) + } + }; + }); + + public static List CreateDistributedHitEvents() + { + var hitEvents = new List(); + + for (int i = 0; i < 50; i++) + { + int count = (int)(Math.Pow(25 - Math.Abs(i - 25), 2)); + + for (int j = 0; j < count; j++) + hitEvents.Add(new HitEvent(i - 25, HitResult.Perfect, new Note(), new Note(), null)); + } + + return hitEvents; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs index ae64a6ea8..2c56af853 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. using System; diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs index 8266a171b..ed26e270a 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. using NUnit.Framework; @@ -7,7 +7,6 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Screens.Ranking.Statistics; -using osu.Game.Tests; using osu.Game.Tests.Visual; using System.Collections.Generic; @@ -18,10 +17,9 @@ public class TestSceneStatisticsPanel : OsuTestScene [Test] public void TestScoreWithStatistics() { - var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo) + var score = new TestKaraokeScoreInfo() { - //TODO : add hit event. - HitEvents = new List() + HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents() }; loadPanel(score); @@ -30,7 +28,7 @@ public void TestScoreWithStatistics() [Test] public void TestScoreWithoutStatistics() { - loadPanel(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); + loadPanel(new TestKaraokeScoreInfo()); } [Test] From fdbcf803b82b984eca9928d83155e21f5cddb1f9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Thu, 2 Jul 2020 22:02:43 +0900 Subject: [PATCH 4/4] Remove unused case and clean-up code. --- .../Ranking/TestKaraokeScoreInfo.cs | 2 +- .../Ranking/TestSceneResultsScreen.cs | 210 +----------------- .../Ranking/TestSceneStatisticsPanel.cs | 4 +- 3 files changed, 6 insertions(+), 210 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs index 6d7c6f547..f759905c8 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestKaraokeScoreInfo.cs @@ -19,7 +19,7 @@ public TestKaraokeScoreInfo() User = new User { - Id = 11111, + Id = 1030492, Username = "andy840119", CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", }; diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs index 2c56af853..633d8ee6f 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneResultsScreen.cs @@ -4,14 +4,12 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Screens; using osu.Framework.Testing; -using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Online.API; using osu.Game.Rulesets.Karaoke.Tests.Beatmaps; @@ -20,9 +18,7 @@ using osu.Game.Screens.Play; using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking.Statistics; -using osu.Game.Tests; using osu.Game.Tests.Visual; -using osuTK; using osuTK.Input; namespace osu.Game.Rulesets.Karaoke.Tests.Ranking @@ -32,126 +28,10 @@ public class TestSceneResultsScreen : OsuManualInputManagerTestScene { protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestKaraokeBeatmap(ruleset); - private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); - - private UnrankedSoloResultsScreen createUnrankedSoloResultsScreen() => new UnrankedSoloResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo)); - - [Test] - public void TestResultsWithoutPlayer() - { - TestResultsScreen screen = null; - OsuScreenStack stack; - - AddStep("load results", () => - { - Child = stack = new OsuScreenStack - { - RelativeSizeAxes = Axes.Both - }; - - stack.Push(screen = createResultsScreen()); - }); - AddUntilStep("wait for loaded", () => screen.IsLoaded); - AddAssert("retry overlay not present", () => screen.RetryOverlay == null); - } - - [Test] - public void TestResultsWithPlayer() - { - TestResultsScreen screen = null; - - AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); - AddUntilStep("wait for loaded", () => screen.IsLoaded); - AddAssert("retry overlay present", () => screen.RetryOverlay != null); - } - - [Test] - public void TestResultsForUnranked() + private TestResultsScreen createResultsScreen() => new TestResultsScreen(new TestKaraokeScoreInfo { - UnrankedSoloResultsScreen screen = null; - - AddStep("load results", () => Child = new TestResultsContainer(screen = createUnrankedSoloResultsScreen())); - AddUntilStep("wait for loaded", () => screen.IsLoaded); - AddAssert("retry overlay present", () => screen.RetryOverlay != null); - } - - [Test] - public void TestShowHideStatisticsViaOutsideClick() - { - TestResultsScreen screen = null; - - AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); - AddUntilStep("wait for loaded", () => screen.IsLoaded); - - AddStep("click expanded panel", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - InputManager.MoveMouseTo(expandedPanel); - InputManager.Click(MouseButton.Left); - }); - - AddAssert("statistics shown", () => this.ChildrenOfType().Single().State.Value == Visibility.Visible); - - AddUntilStep("expanded panel at the left of the screen", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - return expandedPanel.ScreenSpaceDrawQuad.TopLeft.X - screen.ScreenSpaceDrawQuad.TopLeft.X < 150; - }); - - AddStep("click to right of panel", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - InputManager.MoveMouseTo(expandedPanel.ScreenSpaceDrawQuad.TopRight + new Vector2(100, 0)); - InputManager.Click(MouseButton.Left); - }); - - AddAssert("statistics hidden", () => this.ChildrenOfType().Single().State.Value == Visibility.Hidden); - - AddUntilStep("expanded panel in centre of screen", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - return Precision.AlmostEquals(expandedPanel.ScreenSpaceDrawQuad.Centre.X, screen.ScreenSpaceDrawQuad.Centre.X, 1); - }); - } - - [Test] - public void TestShowHideStatistics() - { - TestResultsScreen screen = null; - - AddStep("load results", () => Child = new TestResultsContainer(screen = createResultsScreen())); - AddUntilStep("wait for loaded", () => screen.IsLoaded); - - AddStep("click expanded panel", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - InputManager.MoveMouseTo(expandedPanel); - InputManager.Click(MouseButton.Left); - }); - - AddAssert("statistics shown", () => this.ChildrenOfType().Single().State.Value == Visibility.Visible); - - AddUntilStep("expanded panel at the left of the screen", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - return expandedPanel.ScreenSpaceDrawQuad.TopLeft.X - screen.ScreenSpaceDrawQuad.TopLeft.X < 150; - }); - - AddStep("click expanded panel", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - InputManager.MoveMouseTo(expandedPanel); - InputManager.Click(MouseButton.Left); - }); - - AddAssert("statistics hidden", () => this.ChildrenOfType().Single().State.Value == Visibility.Hidden); - - AddUntilStep("expanded panel in centre of screen", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - return Precision.AlmostEquals(expandedPanel.ScreenSpaceDrawQuad.Centre.X, screen.ScreenSpaceDrawQuad.Centre.X, 1); - }); - } + HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents() + }); [Test] public void TestShowStatisticsAndClickOtherPanel() @@ -181,24 +61,6 @@ public void TestShowStatisticsAndClickOtherPanel() AddAssert("expanded panel still expanded", () => expandedPanel.State == PanelState.Expanded); } - [Test] - public void TestFetchScoresAfterShowingStatistics() - { - DelayedFetchResultsScreen screen = null; - - AddStep("load results", () => Child = new TestResultsContainer(screen = new DelayedFetchResultsScreen(new TestScoreInfo(new KaraokeRuleset().RulesetInfo), 3000))); - AddUntilStep("wait for loaded", () => screen.IsLoaded); - AddStep("click expanded panel", () => - { - var expandedPanel = this.ChildrenOfType().Single(p => p.State == PanelState.Expanded); - InputManager.MoveMouseTo(expandedPanel); - InputManager.Click(MouseButton.Left); - }); - - AddUntilStep("wait for fetch", () => screen.FetchCompleted); - AddAssert("expanded panel still on screen", () => this.ChildrenOfType().Single(p => p.State == PanelState.Expanded).ScreenSpaceDrawQuad.TopLeft.X > 0); - } - private class TestResultsContainer : Container { [Cached(typeof(Player))] @@ -220,27 +82,18 @@ public TestResultsContainer(IScreen screen) private class TestResultsScreen : ResultsScreen { - public HotkeyRetryOverlay RetryOverlay; - public TestResultsScreen(ScoreInfo score) : base(score) { } - protected override void LoadComplete() - { - base.LoadComplete(); - - RetryOverlay = InternalChildren.OfType().SingleOrDefault(); - } - protected override APIRequest FetchScores(Action> scoresCallback) { var scores = new List(); for (int i = 0; i < 20; i++) { - var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo); + var score = new TestKaraokeScoreInfo(); score.TotalScore += 10 - i; scores.Add(score); } @@ -250,60 +103,5 @@ protected override APIRequest FetchScores(Action> scoresC return null; } } - - private class DelayedFetchResultsScreen : TestResultsScreen - { - public bool FetchCompleted { get; private set; } - - private readonly double delay; - - public DelayedFetchResultsScreen(ScoreInfo score, double delay) - : base(score) - { - this.delay = delay; - } - - protected override APIRequest FetchScores(Action> scoresCallback) - { - Task.Run(async () => - { - await Task.Delay(TimeSpan.FromMilliseconds(delay)); - - var scores = new List(); - - for (int i = 0; i < 20; i++) - { - var score = new TestScoreInfo(new KaraokeRuleset().RulesetInfo); - score.TotalScore += 10 - i; - scores.Add(score); - } - - scoresCallback?.Invoke(scores); - - Schedule(() => FetchCompleted = true); - }); - - return null; - } - } - - private class UnrankedSoloResultsScreen : SoloResultsScreen - { - public HotkeyRetryOverlay RetryOverlay; - - public UnrankedSoloResultsScreen(ScoreInfo score) - : base(score) - { - Score.Beatmap.OnlineBeatmapID = 0; - Score.Beatmap.Status = BeatmapSetOnlineStatus.Pending; - } - - protected override void LoadComplete() - { - base.LoadComplete(); - - RetryOverlay = InternalChildren.OfType().SingleOrDefault(); - } - } } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs index ed26e270a..0cde64945 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Ranking/TestSceneStatisticsPanel.cs @@ -4,11 +4,9 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Screens.Ranking.Statistics; using osu.Game.Tests.Visual; -using System.Collections.Generic; namespace osu.Game.Rulesets.Karaoke.Tests.Ranking { @@ -17,7 +15,7 @@ public class TestSceneStatisticsPanel : OsuTestScene [Test] public void TestScoreWithStatistics() { - var score = new TestKaraokeScoreInfo() + var score = new TestKaraokeScoreInfo { HitEvents = TestSceneHitEventTimingDistributionGraph.CreateDistributedHitEvents() };