From 7f8799169b45070b43d835328eb31d3bf033c15c Mon Sep 17 00:00:00 2001 From: normalid Date: Wed, 3 Jul 2024 23:09:21 +0800 Subject: [PATCH] Add test and optimize the performance --- .../Rulesets/Scoring/ScoreProcessorTest.cs | 67 +++++++++++++++++-- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 1 - 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs index 1647fbee42..1c52955e1f 100644 --- a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs +++ b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs @@ -388,37 +388,92 @@ namespace osu.Game.Tests.Rulesets.Scoring [Test] public void TestNormalGrades() { - scoreProcessor.ApplyBeatmap(new Beatmap()); + const int count_judgements = 200; + + beatmap = new TestBeatmap(new RulesetInfo()) + { + HitObjects = new List(Enumerable.Repeat(new TestHitObject(HitResult.Great), count_judgements)) + }; + scoreProcessor.ApplyBeatmap(beatmap); Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.X)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.X)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); - scoreProcessor.Accuracy.Value = 0.99f; + // beatmap.HitObjects.Count -100 for simulating the situation of playing in progress + for (int i = 0; i < beatmap.HitObjects.Count - 100; i++) + { + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[i], beatmap.HitObjects[i].Judgement) + { + Type = i == beatmap.HitObjects.Count - 101 ? HitResult.Ok : HitResult.Perfect + }); + } Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.S)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.S)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); } [Test] public void TestSilverGrades() { - scoreProcessor.ApplyBeatmap(new Beatmap()); + const int count_judgements = 200; + + beatmap = new TestBeatmap(new RulesetInfo()) + { + HitObjects = new List(Enumerable.Repeat(new TestHitObject(HitResult.Great), count_judgements)) + }; + scoreProcessor.ApplyBeatmap(beatmap); + Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.X)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.X)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); scoreProcessor.Mods.Value = new[] { new OsuModHidden() }; Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.XH)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.XH)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); - scoreProcessor.Accuracy.Value = 0.99f; + // beatmap.HitObjects.Count -100 for simulating the situation of playing in progress + for (int i = 0; i < beatmap.HitObjects.Count - 100; i++) + { + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[i], beatmap.HitObjects[i].Judgement) + { + Type = i == beatmap.HitObjects.Count - 101 ? HitResult.Ok : HitResult.Perfect + }); + } Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.SH)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.SH)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); } [Test] public void TestSilverGradesModsAppliedFirst() { + const int count_judgements = 200; + + beatmap = new TestBeatmap(new RulesetInfo()) + { + HitObjects = new List(Enumerable.Repeat(new TestHitObject(HitResult.Great), count_judgements)) + }; + scoreProcessor.Mods.Value = new[] { new OsuModHidden() }; - scoreProcessor.ApplyBeatmap(new Beatmap()); + scoreProcessor.ApplyBeatmap(beatmap); Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.XH)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.XH)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); - scoreProcessor.Accuracy.Value = 0.99f; + // beatmap.HitObjects.Count -100 for simulating the situation of playing in progress + for (int i = 0; i < beatmap.HitObjects.Count - 100; i++) + { + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[i], beatmap.HitObjects[i].Judgement) + { + Type = i == beatmap.HitObjects.Count - 101 ? HitResult.Ok : HitResult.Perfect + }); + } Assert.That(scoreProcessor.Rank.Value, Is.EqualTo(ScoreRank.SH)); + Assert.That(scoreProcessor.MaximumRank.Value, Is.EqualTo(ScoreRank.SH)); + Assert.That(scoreProcessor.MinimumRank.Value, Is.EqualTo(ScoreRank.D)); } private class TestJudgement : Judgement diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 25b3188e86..1d238cbbda 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -204,7 +204,6 @@ namespace osu.Game.Rulesets.Scoring public ScoreProcessor(Ruleset ruleset) { Ruleset = ruleset; - Accuracy.ValueChanged += _ => updateRank(); Combo.ValueChanged += combo => HighestCombo.Value = Math.Max(HighestCombo.Value, combo.NewValue);